from itsdangerous import TimedJSONWebSignatureSerializer as TJSS

# 签名加密
def generate_sign_openid(openid):
    # 创建对象
    serializer = TJSS(secret_key='oauth', expires_in=600)

    # 加密
    # dumps( Like :meth:`.Serializer.dumps` but creates a JSON WebSignature.)
    sign_openid = serializer.dumps({'openid':openid})

    # 返回结果
    return sign_openid.decode()

# 签名解密

def decode_sign_openid(data):

    # 创建对象
    serializer = TJSS(secret_key='oauth', expires_in=600)

    # 解密
    try:
        data_dict = serializer.loads(data)
    except:
        return None

    # 返回结果
    return data_dict.get('openid')





